#include <iostream>
#include <vector>

using namespace std;

void trace(vector<vector<int>> matrix,vector<vector<int>> &path_trace,vector<vector<int>> &path_best,int i,int j);
int main()

{
    int row=0,col=0;
    while(cin>>row>>col)
    {
        vector<vector<int>> matrix(row,vector<int>(col,0));
        for(int i=0;i<row;i++)
            for (int j=0;j<col;j++)
                cin>>matrix[i][j];
         vector<vector<int>> path_trace;   
         vector<vector<int>> path_best;   
        trace(matrix,path_trace,path_best,0,0);   ///注意传递的初始 ij
        for(auto ele:path_best)
        {
            cout<<"("<<ele[0]<<","<<ele[1]<<")"<<endl;
        }
        
        
    }
    
    return 0;
}






void trace(vector<vector<int>> matrix,vector<vector<int>> &path_trace,vector<vector<int>> &path_best,int i,int j)
{
    
    matrix[i][j]=1;   ///注意这里
    path_trace.push_back({i,j});  ///{i,j}  是一个 vector<int> 型的值
    if(i==matrix.size()-1 && j==matrix[0].size()-1)
    {
        if(  path_best.size()==0 || path_trace.size()<path_best.size())   /// 注意path_best 的首次一定要赋值
        {
            path_best= path_trace;
        }
        return;
    }
    
    if(i-1>=0 && matrix[i-1][j]==0)  //向上走的条件
    {
        trace(matrix,path_trace,path_best,i-1,j);
    }
    if(i+1<matrix.size() &&  matrix[i+1][j]==0)  //向下走的条件
    {
        trace(matrix,path_trace,path_best,i+1,j);
    }
    if(j-1>=0 && matrix[i][j-1]==0)  //向左走的条件
    {
        trace(matrix,path_trace,path_best,i,j-1);
    }
    if(j+1<matrix[0].size() && matrix[i][j+1]==0)  //向上走的条件
    {
        trace(matrix,path_trace,path_best,i,j+1);
    }
    matrix[i][j]=0;
    path_trace.pop_back(); //注意这里   vector popback的独特功效
    
    
   
}